import 'package:flutter/material.dart';
import 'package:shenling_logistics/pages/index.dart';
import 'package:shenling_logistics/pages/login/index.dart';
import 'package:shenling_logistics/pages/setting/index.dart';
import 'package:shenling_logistics/utils/Auth.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => Index(),
        '/login': (context) => LoginPage(),
        '/setting': (context) => SettingPage(),
      },
      onGenerateRoute: (settings) {
        final auth = Auth();
        final token = auth.getToken() ?? '';

        if (token.isNotEmpty && settings.name != '/login') {
          return MaterialPageRoute(builder: (context) => const Index());
        }
        return null;
      },
      initialRoute: '/',
    ),
  );
}
